package com.anjie.powerproject.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 读取配置文件中配置的url
 */
@RestController
@RequestMapping(value = "url")
@PropertySource(value = {"classpath:url.properties"}, encoding = "UTF-8", name = "url.properties")
public class UrlController {
    @Value("#{${project.admin.url}}")
    private Map<String, String> urlMap;

    @RequestMapping(value = "get/{type}", method = RequestMethod.GET)
    public Map<String, Object> get(@PathVariable String type) {
        Map<String, Object> resultMap = new HashMap<>();

        String url = urlMap.get(type);
        if (url != null && !url.equals("")) {
            resultMap.put("url", url);
        } else {
            resultMap.put("error", "请检查配置文件或者UrlController");
        }

        return resultMap;
    }
}
